package com.chineseall.rebirth.bridge.service;

import jmind.core.support.LogUtil;
import jmind.core.util.DataUtil;
import jmind.core.util.GlobalConstants;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chineseall.rebirth.bridge.zedis.Zedis;
import com.chineseall.rebirth.bridge.zedis.ZedisConsts;

/**
 * 道具服务
 * @author wbxie
 * 2014-1-18
 */
@Service
public class PropsService {
    private final Zedis zedis = new Zedis(ZedisConsts.ENV_PROPS);

    // 总pk票
    public int getPk(int uid) {
        String str = zedis.get(ZedisConsts.PORPS_PK + uid);
        try {
            JSONObject json = JSON.parseObject(str);
            if (json != null && json.containsKey("count"))
                return json.getIntValue("count");
            else
                return 0;

        } catch (Exception e) {
            LogUtil.debug("getpk uid=" + uid + ",json=" + str);
            return 0;
        }
    }

    // 当日剩余鲜花数
    public int getRestFlowerCount(int uid, int userLevel) {
        try {
            String s = zedis.get(ZedisConsts.PORPS_FLOWER_TODAY + uid + GlobalConstants.DELIM + userLevel);
            return DataUtil.toInt(s);
        } catch (Exception e) {
            LogUtil.getLogger(getClass()).error("uid" + "--" + userLevel, e);
        }
        return 0;

    }

    public static void main(String[] args) {
        int string = new PropsService().getPk(1);
        System.out.println(string);
    }

}
